home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_DrawGauge.c < prev    next >
C/C++ Source or Header  |  1999-01-02  |  5KB  |  260 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1999 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #include "Assert.h"
  15.  
  16. #ifdef DO_GAUGE_KIND    /* Support code */
  17.  
  18. VOID
  19. LTP_GaugeFill(struct RastPort *rp,LONG pen,ObjectNode *node,LONG left,LONG right,LONG height)
  20. {
  21.     if(right)
  22.     {
  23.         LTP_SetAPen(rp,pen);
  24.         LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,right - left,height);
  25.     }
  26. }
  27.  
  28. VOID
  29. LTP_DrawTick(LayoutHandle *Handle,ObjectNode *Node,LONG Left,LONG Top)
  30. {
  31.     struct RastPort *rp = &Handle->RPort;
  32.  
  33.     Left += Node->Left;
  34.  
  35.     LTP_SetAPen(rp,Handle->ShadowPen);
  36.     LTP_DrawLine(rp,Left,Top,Left,Top + 1);
  37.  
  38.     LTP_SetAPen(rp,Handle->ShinePen);
  39.     LTP_DrawLine(rp,Left + 1,Top,Left + 1,Top + 1);
  40. }
  41.  
  42. VOID
  43. LTP_DrawGauge(LayoutHandle *handle,ObjectNode *node,LONG percent,BOOL fullRefresh)
  44. {
  45.     struct RastPort *rp = &handle->RPort;
  46.     LONG height = node->Height - (1 + 1);
  47.     LONG width = node->Width - (2 + 2);
  48.     UWORD *Pens = handle->DrawInfo->dri_Pens;
  49.     LONG fillPen = Pens[FILLPEN];
  50.     LONG backPen = Pens[BACKGROUNDPEN];
  51.     BOOL continuous;
  52.  
  53.     if(fullRefresh)
  54.     {
  55.         LTP_EraseBox(rp,node->Left,node->Top,node->Width,node->Height);
  56.  
  57.         if(node->Special.Gauge.NoTicks)
  58.             LTP_DrawBevelBox(handle,node);
  59.         else
  60.         {
  61.             LONG top = node->Top + node->Height - (handle->GlyphHeight + 2);
  62.  
  63.             LTP_DrawBevel(handle,node->Left,node->Top,node->Width,node->Height - (handle->InterHeight + handle->GlyphHeight + 2));
  64.  
  65.             LTP_SetPens(rp,handle->TextPen,0,JAM1);
  66.  
  67.             LTP_PrintText(rp,"0%",2,node->Left,top);
  68.             LTP_PrintText(rp,"100%",4,node->Left + node->Width - TextLength(rp,"100%",4),top);
  69.  
  70.             if(node->Width >= TextLength(rp,"0%50%100%",9) + 4 * handle->GlyphWidth)
  71.             {
  72.                 LONG i,left,total = node->Width - 2;
  73.  
  74.                 LTP_PrintText(rp,"50%",3,node->Left + (node->Width - TextLength(rp,"50%",3)) / 2,top);
  75.  
  76.                 top -= handle->InterHeight;
  77.  
  78.                 for (i = 0 ; i < 5 ; i++)
  79.                 {
  80.                     left = (total * i) / 4;
  81.  
  82.                     LTP_DrawTick(handle,node,left,top);
  83.                 }
  84.             }
  85.             else
  86.             {
  87.                 LONG i,left,total = node->Width - 2;
  88.  
  89.                 top -= handle->InterHeight;
  90.  
  91.                 for (i = 0; i < 3; i++)
  92.                 {
  93.                     left = (total * i) / 2;
  94.  
  95.                     LTP_DrawTick(handle,node,left,top);
  96.                 }
  97.             }
  98.         }
  99.     }
  100.  
  101.     if(node->Special.Gauge.Discrete)
  102.     {
  103.         if(width < 60)
  104.             continuous = TRUE;
  105.         else
  106.             continuous = FALSE;
  107.     }
  108.     else
  109.         continuous = TRUE;
  110.  
  111.     if(!node->Special.Gauge.NoTicks)
  112.         height -= handle->InterHeight + handle->GlyphHeight + 2;
  113.  
  114.     if(node->Special.Gauge.InfoLength && node->Special.Gauge.InfoText[0])
  115.     {
  116.         struct TextExtent Extent;
  117.         LONG len;
  118.         LONG textPen;
  119.         LONG mode;
  120.         LONG right;
  121.  
  122.         if(continuous)
  123.             LTP_GaugeFill(rp,fillPen,node,0,right = (width * percent) / 100,height);
  124.         else
  125.         {
  126.             LONG count;
  127.             LONG left;
  128.  
  129.             left = right = 0;
  130.  
  131.             if(count = (10 * percent) / 100)
  132.             {
  133.                 LONG chunk = width / 10,i;
  134.  
  135.                 for(i = 0 ; i < count ; i++)
  136.                 {
  137.                     LTP_SetAPen(rp,fillPen);
  138.                     LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,(chunk - 1),height);
  139.  
  140.                     left += chunk;
  141.                     right += chunk;
  142.  
  143.                     LTP_SetAPen(rp,backPen);
  144.                     LTP_FillBox(rp,node->Left + 2 + right - 1,node->Top + 1,1,height);
  145.                 }
  146.             }
  147.         }
  148.  
  149.         if(right < width)
  150.             LTP_GaugeFill(rp,backPen,node,right,width,height);
  151.  
  152.         if(handle->TextPen == fillPen)
  153.             textPen = Pens[FILLTEXTPEN];
  154.         else
  155.             textPen = handle->TextPen;
  156.  
  157.         if(textPen == fillPen || textPen == backPen)
  158.             mode = JAM1 | COMPLEMENT;
  159.         else
  160.             mode = JAM1;
  161.  
  162.         LTP_SetPens(rp,textPen,0,mode);
  163.  
  164.         len = TextFit(rp,node->Special.Gauge.InfoText,strlen(node->Special.Gauge.InfoText),&Extent,NULL,1,width,32767);
  165.  
  166.         LTP_PrintText(rp,node->Special.Gauge.InfoText,len,node->Left + 2 + (width - Extent.te_Width) / 2,node->Top + 1 + (height - handle->GlyphHeight) / 2);
  167.  
  168.         if(mode != JAM1)
  169.             SetDrMd(rp,JAM1);
  170.     }
  171.     else
  172.     {
  173.         LONG left = 0,right = 0,pen = 0;    /* Initialize these for the sake of the compiler. */
  174.         BOOL drawIt = FALSE;
  175.  
  176.         if(continuous)
  177.         {
  178.             if(node->Current < percent)
  179.             {
  180.                 left    = (width * node->Current) / 100;
  181.                 right    = (width * percent) / 100;
  182.                 pen        = fillPen;
  183.                 drawIt    = TRUE;
  184.             }
  185.             else
  186.             {
  187.                 if(node->Current > percent)
  188.                 {
  189.                     left    = (width * percent) / 100;
  190.                     right    = (width * node->Current) / 100;
  191.                     pen        = backPen;
  192.                     drawIt    = TRUE;
  193.                 }
  194.             }
  195.         }
  196.         else
  197.         {
  198.             LONG count;
  199.  
  200.             count = (10 * percent) / 100;
  201.  
  202.             if(fullRefresh || count != node->Special.Gauge.LastPercentage)
  203.             {
  204.                 node->Special.Gauge.LastPercentage = count;
  205.  
  206.                 right = 0;
  207.  
  208.                 if(count)
  209.                 {
  210.                     LONG chunk = width / 10,i;
  211.  
  212.                     left = 0;
  213.  
  214.                     for(i = 0 ; i < count ; i++)
  215.                     {
  216.                         LTP_SetAPen(rp,fillPen);
  217.                         LTP_FillBox(rp,node->Left + 2 + left,node->Top + 1,(chunk - 1),height);
  218.  
  219.                         left += chunk;
  220.                         right += chunk;
  221.  
  222.                         LTP_SetAPen(rp,backPen);
  223.                         LTP_FillBox(rp,node->Left + 2 + right - 1,node->Top + 1,1,height);
  224.                     }
  225.                 }
  226.  
  227.                 if(right < width)
  228.                 {
  229.                     left    = right;
  230.                     right    = width;
  231.                     pen        = backPen;
  232.                     drawIt    = TRUE;
  233.                 }
  234.             }
  235.         }
  236.  
  237.         if(drawIt)
  238.             LTP_GaugeFill(rp,pen,node,left,right,height);
  239.     }
  240.  
  241.     if(node->Disabled)
  242.     {
  243.         UWORD Height;
  244.  
  245.         if(node->Special.Gauge.NoTicks)
  246.             Height = 0;
  247.         else
  248.             Height = handle->InterHeight + handle->GlyphHeight + 2;
  249.  
  250.         LTP_GhostBox(rp,node->Left + 2,node->Top + 1,node->Width - 4,node->Height - 2 - Height,Pens[SHADOWPEN]);
  251.     }
  252.  
  253.     node->Current = percent;
  254.  
  255.     LTP_PutStorage(node);
  256. }
  257.  
  258. #endif    /* DO_GAUGE_KIND */
  259.  
  260.